package com.qf.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.mapper.DtsCouponUserMapper;
import com.qf.pojo.DtsBrand;
import com.qf.pojo.DtsCoupon;
import com.qf.pojo.DtsCouponUser;
import com.qf.service.DtsCouponService;
import com.qf.util.ResponseUtil;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin("*")
@RequestMapping("/coupon")
public class CouponController {
    @Autowired
    private DtsCouponService couponService;


    @RequestMapping("/read")
    public Object read(Integer id){
        List<DtsCoupon> data = couponService.readCoupon(id);

        return ResponseUtil.ok(data);
    }

    @RequestMapping("/list")
    public Object list(Integer id, String name,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @RequestParam(defaultValue = "add_time") String sort,
                       @RequestParam(defaultValue = "desc") String order) {


        IPage<DtsCoupon> resultPage = couponService.queryBrandPage(id, name, page, limit, sort, order);

        List<DtsCoupon> list = resultPage.getRecords();

        long total = resultPage.getTotal();
        Map<String, Object> data = new HashMap<>();

        data.put("total", total);
        data.put("items", list);

        return ResponseUtil.ok(data);
    }

    @RequestMapping("/listuser")
    public Object listuser(@RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "10") Integer limit,
                           @RequestParam(defaultValue = "add_time") String sort,
                           @RequestParam(defaultValue = "desc") String order){
        IPage<DtsCouponUser> resultPage = couponService.queryCouponUserPage(page,limit,sort,order);

        List<DtsCouponUser> list = resultPage.getRecords();

        long total = resultPage.getTotal();
        Map<String, Object> data = new HashMap<>();

        data.put("total", total);
        data.put("items", list);

        return ResponseUtil.ok(data);

    }
}
